package com.example.juc.demo;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo {

    public static final int num = 5;

    public static void main(String[] args) throws InterruptedException {


        CountDownLatch countDownLatch = new CountDownLatch(num);

        for (int i = 0; i < num; i++) {

            new Thread(() -> {
                System.out.println(Thread.currentThread().getName()+"同学离开了教室");
                countDownLatch.countDown();
            }, String.valueOf(i)).start();
        }

        countDownLatch.await();

        System.out.println("关门");
    }
}
